//
//  SyncHandlerGetAsignaturas.m
//  MasterUabApp
//
//  Created by Developer on 14/10/13.
//  Copyright (c) 2013 Owlab. All rights reserved.
//


//----IMPORTS-->
#import "SyncHandlerGetAsignaturas.h"
#import "EConsts.h"
#import "ECommon.h"
#import "Alumno.h"
//<-------------

@implementation SyncHandlerGetAsignaturas


- (int) getType
{
    return SYNC_HANDLER_TYPE_NONE;
}

- (NSString*) getMethod
{
    return @"services.php?listaAsignaturasAlumno";
}

- (void) fillRequestParams:(NSMutableDictionary*)data
{
    [super fillRequestParams:data];
    [data setValue:_AlumnoID   forKey:@"id"];
}

- (BOOL) processJSON:(id)data;
{
    BOOL ok = YES;
    
    AlumnoArray *alumnoArray = (AlumnoArray*)self.delegate;
    [alumnoArray.arrayAsignaturas removeAllObjects];
    
    NSArray*arr = (NSArray*)data;
    
    NSDictionary *objData;
    for (int i = 0; i<arr.count && ok && !self.cancelled;i++)
    {
        objData = [arr objectAtIndex:i];
        Asignatura *asignatura = [[Asignatura alloc]init];
        asignatura.AsignaturaNombre     = [self stringFromJSON:[objData objectForKey:@"AsignaturaNombre"]];
        asignatura.AsignaturaId         = [self stringFromJSON:[objData objectForKey:@"AsignaturaId"]];
        asignatura.AsignaturaCreditos   = [self stringFromJSON:[objData objectForKey:@"AsignaturaCreditos"]];
        [alumnoArray.arrayAsignaturas addObject:asignatura];
    }
    
    [self syncDone:YES object:alumnoArray];
    
    return ok;
}

@end